/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package service.impl;

import java.util.List;
import pojo.Category;
import service.ICategoryService;
/**
 *
 * @author administrator
 */
public class CategoryServiceImpl<T extends Category> extends ServiceImpl<T>
                 implements ICategoryService<T>{
    public List<T> listCategory(){
        return this.getDao().list("select c from Category c");
    }

    public T getCategory(int categoryID) {
        List<T> category = this.getDao().createQuery(
                " select c from Category c "
                + " where c.categoryId = :id ").setParameter("id", categoryID).list();

        if (category.size() > 0) {
            return category.get(0);
        }

        return null;
    }

    public void increaseArticle(T category)
    {
        category.setArticleCount(category.getArticleCount()+1);
        this.getDao().save(category);
    }

    public void decreaseArticle(T category)
    {
        category.setArticleCount(category.getArticleCount()-1);
        this.getDao().save(category);
    }

    public void updateCategory(T category)
    {
        this.getDao().save(this.getDao().merge(category));
    }
    
}
